package com.shiyo.spring.basic_di.d_complexfield.bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Dog {

    @Value("dogdog")
    private String name;

    //1 Autowired 注解可以标注在属性上
    //@Autowired(required = false)
    private Person person;

    //2 Autowired 注解可以标注在构造器上，构造器的参数会从容器中获取
//    @Autowired(required = false)
//    public Dog(Person person) {
//        this.person = person;
//    }

    //3 Autowired 注解可以标注在set方法上
    @Autowired(required = false)
    //@Qualifier("master")
    public void setPerson(Person person) {
        this.person = person;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", person=" + person +
                '}';
    }
}
